package com.zhangyu.shadow.repair.delegate.maintain;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;

import com.zhangyu.shadow.repair.R;

import st.lib.base.util.utilcode.util.ToastUtils;

/**
 * @author zhangyu
 * @date 2018/12/6
 */

public class DeleteDialog extends Dialog {
    private OnConfirmListener mConfirmListener;

    public DeleteDialog(@NonNull Context context, OnConfirmListener listener) {
        super(context);
        mConfirmListener = listener;
        setTitle("报修删除");
        View view = LayoutInflater.from(context).
                inflate(R.layout.dialog_delete, null);
        final EditText editText = view.findViewById(R.id.et_reason);
        view.findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
        view.findViewById(R.id.btn_confirm).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String reason = editText.getText().toString();
                if (reason.isEmpty()) {
                    ToastUtils.showShortSafe("请输入删除原因");
                    return;
                }
                dismiss();
                if (mConfirmListener != null) {
                    mConfirmListener.onConfirm(reason);
                }
            }
        });
        setContentView(view);
    }

    public interface OnConfirmListener {
        public void onConfirm(String reason);
    }
}
